package com.jd.gitdemo0702.controller;

import com.jd.gitdemo0702.bean.R;
import com.jd.gitdemo0702.bean.Worker;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {

    // 假设前端应用 所在服务器 www.jjc.com
    //    // 后端应用    ........... www.master.cn
    //    // @CrossOrigin(origins = {"jjc.com"})
    @GetMapping("/worker")
    public R<Worker> ws() {
        // 假设来自数据库
        Worker worker = new Worker("1", "张三", 18, "男");
        R<Worker> r = R.success("200","查询成功",worker);
        return r;
    }

    @GetMapping("/worker/{wid}")
    public R<Worker> ws2(@PathVariable String wid) {
        // 假设来自数据库
        Worker worker = new Worker(wid, "工人", 22, "男");
        R<Worker> r = R.success("200","查询成功",worker);
        return r;
    }
}
